package com.xtedu.examproject.service;

import com.xtedu.examproject.dao.base.ExamQuestionDao;
import com.xtedu.examproject.dao.impl.ExamQuestionDaoImpl;
import com.xtedu.examproject.entity.ExamQuestion;
import com.xtedu.examproject.util.PageHelper;

import java.util.List;
import java.util.Map;

public class ExamQuestionService {
    private ExamQuestionDao examQuestionDao;

    public ExamQuestionService() {
        examQuestionDao = new ExamQuestionDaoImpl();
    }

    public int insert(ExamQuestion examQuestion) throws Exception {
        return examQuestionDao.insert(examQuestion);
    }

    public int[] insertBatch(List<Map<String, Object>> questions) {
        return examQuestionDao.insertBatch(questions);
    }

    public int delete(ExamQuestion examQuestion) throws Exception {
        return examQuestionDao.delete(examQuestion);
    }

    public int[] deleteBatch(List<Integer> questionIds) {
        return examQuestionDao.deleteBatch(questionIds);
    }

    public int update(ExamQuestion examQuestion) throws Exception {
        return examQuestionDao.update(examQuestion);
    }

    public ExamQuestion findById(int examQuestionId) throws Exception {
        return examQuestionDao.findById(examQuestionId);
    }

    public List<ExamQuestion> findAll() throws Exception {
        return examQuestionDao.findAll();
    }

    public PageHelper findAllByPage(int pageIndex, int pageSize) throws Exception {
        return examQuestionDao.findAllByPage(pageIndex, pageSize);
    }

    public PageHelper findPageByType(int questionTypeId, int pageIndex, int pageSize) {
        return examQuestionDao.findPageByType(questionTypeId, pageIndex, pageSize);
    }

    public PageHelper findPageByCourse(int courseId, int pageIndex, int pageSize) {
        return examQuestionDao.findPageByCourse(courseId, pageIndex, pageSize);
    }

    public int deleteById(int examQuestionId) throws Exception {
        return examQuestionDao.deleteById(examQuestionId);
    }

    public List<ExamQuestion> randomQuestions(int courseId, int questionTypeId, int questionCount) {
        return examQuestionDao.randomQuestions(courseId, questionTypeId, questionCount);
    }

    /**
     * 判断该题目是否在未开始的考试中
     *
     * @param questionId 题目id
     * @return true表示此题在未开考状态的试卷中，false表示此题不在未开考状态的试卷中
     */
    public Boolean isNotInEndExam(int questionId) {
        return examQuestionDao.isNotInEndExam(questionId);
    }

    public List<Map<String, Object>> getQuestionTypeStats() throws Exception{
        return examQuestionDao.getQuestionTypeStats();
    }

    public PageHelper<ExamQuestion> findPageByCourseAndType(Integer courseId, Integer questionTypeId, int pageIndex, int pageSize){
        return examQuestionDao.findPageByCourseAndType(courseId, questionTypeId, pageIndex, pageSize);
    }

    /**
     * 搜索题目
     */
    public PageHelper<ExamQuestion> searchQuestions(Integer courseId, Integer questionTypeId, String searchText, int pageIndex, int pageSize) throws Exception {
        return examQuestionDao.searchQuestions(courseId, questionTypeId, searchText, pageIndex, pageSize);
    }
}
